<?php
/**
 * Created by PhpStorm.
 * User: zhj
 * Date: 2019/1/16
 * Time: 17:03
 */
namespace app\common\model;
use think\Controller;
use think\Db;

class Car extends ModelBase{

    public function search($where = [], $field = true, $order = '', $paginate = 0)
    {
        $list = $this->getList($where, $field, $order, $paginate);

        return $list;
    }


    public function add($data)
    {
        $car = new Car();
        //首先判断该用户是否存在该商品,存在则在原来的基础上加上现在的数字
        $res =$car->where(['userid'=>$data['userid'],'goodsid'=>$data['goodsid'],'status'=>1])->find();
        if($res){
          $carRes = $car->where(['userid'=>$data['userid'],'goodsid'=>$data['goodsid'],'status'=>1])->setInc('num',$data['num']);
        }else{
            $carRes = $car->insert($data);
        }
        return $carRes;
    }

    public function getByids($where=1)
    {
        $map['status'] = 1;
        $res = Db::name('car')->where('id','in',implode(',',$where))->where($map)->select();
        if($res){
            return $res;
        }else{
            return false;
        }
    }
}